class WeixinGroup < ActiveRecord::Base
	has_many :weixin_users

	def self.fetch
		begin
			groups = $client.groups.result["groups"]
		rescue 
			raise "获取分组失败" 
		end
		groups.each do |group|
			 self.find_or_create_by(wx_id: group['id']) do |g|
			 	g.name = group['name']
			 	g.count = group["count"]
			 end
		end
	end
end
